<?php 
/*$your_email ='yourname@your-website.com';// <<=== update to your email address

$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
    
    
    
    
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    
    ///------------Do Validations-------------
    if(empty($name)||empty($visitor_email))
    {
        $errors .= "\n Name and Email are required fields. ";    
    }
    if(IsInjected($visitor_email))
    {
        $errors .= "\n Bad email value!";
    }
    if(empty($_SESSION['6_letters_code'] ) ||
      strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
    {
    //Note: the captcha code is compared case insensitively.
    //if you want case sensitive match, update the check above to
    // strcmp()
        $errors .= "\n The captcha code does not match!";
    }
    
    if(empty($errors))
    {
        //send the email
        $to = $your_email;
        $subject="New form submission";
        $from = $your_email;
        $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
        
        $body = "A user  $name submitted the contact form:\n".
        "Name: $name\n".
        "Email: $visitor_email \n".
        "Message: \n ".
        "$user_message\n".
        "IP: $ip\n";    
        
        $headers = "From: $from \r\n";
        $headers .= "Reply-To: $visitor_email \r\n";
        
        mail($to, $subject, $body,$headers);
        
        header('Location: thank-you.html');
    }
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}*/
?>
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!-->
<html lang="en">
<!--<![endif]-->
<head>
<!-- Basic Page Needs
	================================================== -->
<meta charset="utf-8">
<title><?php echo TITLE; ?></title>
<meta name="description" content="<?php echo DESCRIPTION; ?>">
<meta name="keyword" content="<?php echo KEYWORDS; ?>">
<meta name="author" content="">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
<?php fnGetMeta(); ?>

<link rel="stylesheet" type="text/css" href="views/css-val/style.css">
<script language="JavaScript">
 $(document).ready(function(){
        $('#send_message').click(function(e){
             
            //Stop form submission & check the validation
            e.preventDefault();
            // Variable declaration
            var name = $('#name').val();
            var email = $('#email').val();
            var phone = $('#phone').val();
             var comnt = $('#comments').val();
            //var capt  =  $('#captcha_code').val();
            var captx=$('#6_letters_codex').val();
            var sdata=$('#comments').val();
            var iChars = "!@#$%^&*+=-\\\;/|\":<>?`~";
            var temp;
            var captchaval=true;
            $('#spcl_error').fadeOut(500);
             // Form field validation
            if(sdata.length != 0)
               {
                   var sdataval=true;
                   //var captchaval=true;
                   for (var a = 0; a < sdata.length; a++) {
                    if (iChars.indexOf(sdata.charAt(a)) != -1) {
                        var sdataval=false;
                        $('#spcl_error').fadeIn(500);
                    }
                    }
               }

            if(comnt.length == 0){
                 comntval = false;
                $('#comnt_error').fadeIn(500);
                
            }else{
                 comntval = true;
                $('#comnt_error').fadeOut(500);
            }
            if(name.length == 0){
                 nameval = false;
                $('#name_error').fadeIn(500);
                
            }else{
                 nameval = true;
                $('#name_error').fadeOut(500);
            }
            if(email.length == 0 || email.indexOf('@') == '-1'){
                 emailval = false;
                $('#email_error').fadeIn(500);
                
            }else{
                emailval=true;
                $('#email_error').fadeOut(500);
            }
            if(phone.length == 0){
                  phoneval = false;
                $('#phone_error').fadeIn(500);
                
            }
             else{
                   phoneval=true;
                $('#phone_error').fadeOut(500);
            }
           
           
           
           
           if(captx.length == 0){
                 captxval = false;
                $('#captx_error').fadeIn(500);
                
            }else{
                 captxval = true;
                 $.post( "<?php echo URL ?>checkSession.php?captcha="+captx, function( data ) { 
                if(data==='false'){   
                    captchaval=false;
                     $('#captx_error').fadeOut(500);
                    $('#capt_error').fadeIn(500);
                }
                else
                {
                     captchaval=true;
                    $('#capt_error').fadeOut(500);   
                    if(nameval==true && emailval==true && phoneval==true && comntval==true && sdataval==true   && captxval==true )
                    {
                        $('#spcl_error').fadeOut(500);
                        $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });
                        $.post('<?php echo URL ?>email.php',$('#contact_form').serialize(),function(res){
                        if(res=='sent')
                        {
                            $('#mail_success').fadeIn(500);
                        }
                        else
                        {
                            $('#mail_fail').fadeIn(500);
                            $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');  
                        }
                        $('#name').val(" "); $('#email').val(" ");$('#phone').val(" ");$('#comments').val(" ");$('#6_letters_codex').val(" ");
                        $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');  
                        });    
                    }       
                }
               
                 });
                $('#captx_error').fadeOut(500);
            }
 
        
        });
 });
 function charonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (!(unicode<48||unicode>57)) {//if not a number
alert("please enter the characters only..");
return false //disable key press
}
} 
}
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if ((unicode<48||unicode>57)&&(unicode!=46)) {//if not a number
alert("please enter the numbers only..");
return false //disable key press
}
} 
}
 
</script>
    </head>
<body class="activateAppearAnimation header3" style="padding-top:0px;">
<!-- Primary Page Layout 
	================================================== --> 
<!-- globalWrapper -->
<div id="globalWrapper" class="localscroll">

            <?php fnGetHeader(); ?>

  <section class="inner_banner">
				<div class="container">
					<div class="row">
						<div class="col-sm-6">
							<ul id="navTrail">
								<li><a href="<?php echo URL; ?>">Home</a></li>
								<li id="navTrailLast">Contact</li>
							</ul>
						</div>
						<div class="col-sm-6 hidden-xs">
							&nbsp;
						</div>
					</div>
				</div>
			</section>
  <section id="content" class="mt30 mb30">
				<div class="container">

					<div class="row">
						<div class="col-sm-4 innerpage">
							<h2 class=""><strong>Our Address in US</strong> </h2>
							 <address>
                            <h3 style="font-size:17px;"><?php echo COMPANY_USA; ?></h3>
              <p> <i class="icon-location"></i><?php echo ADDRESS; ?><br>
                
                <i class="icon-phone"></i>&nbsp;<?php echo TEL;?> <br>
                
                <i class="icon-mail-alt"></i>&nbsp;<a href="mailto:<?php echo MAIL;?>"><?php echo MAIL;?></a> </p>
              </address>
                                                        <h2 class=""><strong>Our Address in India</strong> </h2>
							 <address>
                             <h3 style="font-size:17px;"><?php echo COMPANY_INDIA; ?></h3>
              <p> <i class="icon-location"></i>&nbsp;<?php echo ADDRESS2; ?><br>
                
                <i class="icon-phone"></i>&nbsp;<?php echo TEL2;?> <br>
                
                <i class="icon-mail-alt"></i>&nbsp;<a href="mailto:<?php echo MAIL2;?>"><?php echo MAIL2;?></a> </p>
              </address>
                                                        
						</div>
                                            
  
    
<form method="post" name="contact_form" action="#" id="contact_form" > 
							<div class="col-sm-4"> 
								<div class="form-group">
							
                                    <label for="email">Name</label>
                                    <div id='name_error' name="name_error" style="display: none; color: red;"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please enter your name.</div>		
									<input type="text" class="form-control" name="name" id="name" placeholder="Enter name"  title="Please enter your name (at least 2 characters)"/>
								</div>
								<div class="form-group">
									
                                    <label for="email">Email</label>
                                    <div id='email_error'  name="email_error" style="color: red; display: none;"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please enter your valid E-mail ID.</div>
									<input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address"/>
								</div>
								<div class="form-group">
									
                                    <label for="phone">Phone</label>
                                    <div id='phone_error' style="color: red; display: none;"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please enter your phone number.</div>
									<input name="phone" class="form-control required digits" type="tel" id="phone" size="30" value="" placeholder="Enter phone" title="Please enter a valid phone number (at least 10 characters)" onkeypress="return numbersonly(event)">
								</div>
							</div>
							<div class="col-sm-4">
								<div class="form-group">
									<label for="comments">Comments</label>
                                    <div style="display: none; color: red;" id="spcl_error"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please don't enter the spcial characters</div>
                                    <div style="display: none; color: red;" id="comnt_error"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please fill the comment</div>
									<textarea name="comment" class="form-control" id="comments" cols="3" rows="15" placeholder="Enter your message…" title="Please enter your message (at least 10 characters)"></textarea>
								</div>
								<fieldset class="clearfix securityCheck">
									<label for="security">Security</label>
									<div class="form-group">
										<!--<img src="<?php echo TEMPLATE; ?>captcha.php" style="margin-left: 5px; margin-bottom: 2px; height: 33px;">-->
                                        <div id='capt_error' style="color: red; display: none;"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please enter valid captcha.</div>
                                        <div style="float: right;">
                                        <img src="<?php echo URL;?>captcha_code_file.php?rand=<?php echo rand();?>" id='captchaimg' style="margin-left: 5px; margin-bottom: 2px; height: 33px;" ></div>
                                        <div style="float: left;">
                                        <div style="display: none; color: red;" id="captx_error"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'>Please enter the captcha code</div>
                                        <input class="required form-control" id="6_letters_codex" name="6_letters_codex" type="text" placeholder="Type Captcha Code">
                                        <input type="hidden" name="captcha_code" id="captcha_code" value="<?php echo @$_SESSION['security_code']; ?>">
									</div>
                                     <span class="btn btn-lg" style="background: none; border: none;"> &nbsp;</span>
                                     <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
                                    </div> 
								</fieldset>
							</div>                        
							<div class="col-md-8">
								<div class="result"></div>
								<input type="submit" name="submit"  id="send_message" class="btn btn-lg" > 
                                 <div id='mail_success' style="display: none; color: green;"><img src='<?php echo TEMPLATE; ?>css-val/images/success.png'>Your message has been sent successfully.</div>
    <div id='mail_fail' style="display: none; color: red;"><img src='<?php echo TEMPLATE; ?>css-val/images/error.png'> Sorry, error occured this time sending your message.</div>
                                
							</div>
						</form>
					</div>
				</div>
			</section>
  <?php fnGetFooter(); ?>
</body>
</html>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
    var img = document.images['captchaimg'];
    img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
    
}
</script>
